package support

import (
	"github.com/hyperledger/fabric-chaincode-go/shim"
	"github.com/hyperledger/fabric-contract-api-go/contractapi"
	"github.com/hyperledger/fabric-samples/asset-kx/chaincode-go/chaincode/asset/api"
)


func ProcessStateQueryResult(result shim.StateQueryIteratorInterface, f func(key string, value []byte) error) error {
	for result.HasNext() {
		next, err := result.Next()
		if err != nil {
			return err
		}
		err = f(next.Key, next.Value)
		if err != nil {
			return err
		}
	}
	result.Close()
	return nil
}

func GenUtxid(stub shim.ChaincodeStubInterface, ctx contractapi.TransactionContextInterface) (string, error) {
	txID := stub.GetTxID()
	return txID, nil
}

func ToAssetInterfaces(assets []assetapi.Asset) []interface{} {
	as := make([]interface{}, len(assets))
	for i, asset := range assets {
		as[i] = asset
	}
	return as
}
